package com.filldream.fastboot.web.controller.pc;

import com.filldream.fastboot.base.entity.SysPost;
import com.filldream.fastboot.base.request.IdSTO;
import com.filldream.fastboot.base.request.pc.sysPost.AddSysPostSTO;
import com.filldream.fastboot.base.request.pc.sysPost.ModifySysPostSTO;
import com.filldream.fastboot.base.request.pc.sysPost.SysPostPageSTO;
import com.filldream.fastboot.common.annotation.Log;
import com.filldream.fastboot.common.annotation.RolePermissions;
import com.filldream.fastboot.common.entity.B;
import com.filldream.fastboot.common.entity.P;
import com.filldream.fastboot.core.service.SysPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

/**
 * @author RickSun
 * @version 1.0
 * @data 2021-09-18 16:06
 * @description PcDatabaseController
 */
@AllArgsConstructor
@Api(tags = "PC-岗位管理")
@RestController
@RequestMapping("/pc/post")
public class PcSysPostController {

    private final SysPostService sysPostService;

    @Log(value = "添加岗位")
    @ApiOperation(value = "添加岗位")
    @PostMapping("/add")
    @RolePermissions(value = "post:add")
    public B add(@RequestBody @Valid AddSysPostSTO addPostSTO){
        return sysPostService.savePost(addPostSTO);
    }

    @Log(value = "岗位列表")
    @ApiOperation(value = "岗位列表")
    @GetMapping("/page")
    @RolePermissions()
    public P<SysPost> list(@Valid SysPostPageSTO sysPostPageSTO){
        return sysPostService.pageList(sysPostPageSTO);
    }

    @Log(value = "修改岗位")
    @ApiOperation(value = "修改岗位")
    @PostMapping("/modify")
    @RolePermissions(value = "post:modify")
    public B modify(@RequestBody @Valid ModifySysPostSTO modifySysPostSTO){
        return sysPostService.modifyPost(modifySysPostSTO);
    }

    @Log(value = "删除岗位")
    @ApiOperation(value = "删除岗位")
    @PostMapping("/del")
    @RolePermissions(value = "post:del")
    public B del(@RequestBody @Valid IdSTO idSTO){
        return B.checkSuccess( sysPostService.removeById(idSTO.getId()) );
    }

}
